﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;




public partial class student_xiugai : System.Web.UI.Page
{

    string Constr = "Server=(local);Integrated Security=true;DataBase=Data;";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            string no = Session["Sno"].ToString();
            txt_no.Text = no;
            txt_no.Enabled = false;
            SqlConnection con = new SqlConnection(Constr);
            con.Open();
            string strcom = "select * from student where ID='" + no + "'";
            SqlCommand com = new SqlCommand(strcom, con);
            try
            {
                SqlDataReader sdr = com.ExecuteReader();
                if (sdr.Read())
                {
                    txt_pwd.Text = sdr["pwd"].ToString();
                    txt_name.Text = sdr["name"].ToString();
                    if(sdr["sex"].ToString()=="男"){
                        Rb1.Checked = true;
                    }else{
                        Rb2.Checked = true;
                    }
                    txt_age.Text = sdr["age"].ToString();
                    txt_class.Text = sdr["class"].ToString();
                }
                else
                {
                    Response.Write("<script language=javascript>alert('查询失败！')</script>");
                }

            }
            catch (Exception ex)
            {

            }
            
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
         string Sno = txt_no.Text.Trim();
        string Sname = txt_name.Text.Trim();
        string Spwd = txt_pwd.Text.Trim();
        int Sage = Convert.ToInt32(txt_age.Text.Trim());
        string Ssex = "";
        if (Rb1.Checked)
            Ssex = "男";
        else
            Ssex = "女";
        string Ssdept = txt_class.Text.Trim();
        SqlConnection con = new SqlConnection(Constr);
        string sqlstr = "update Student set pwd='" + Spwd + "',name='" + Sname + "',sex='" + Ssex + "',age=" + Sage + ",class='" + Ssdept + "'where ID='" + Sno + "'";
        SqlCommand com = new SqlCommand(sqlstr, con);
        try
        {
            con.Open();
            com.ExecuteNonQuery();
            Response.Write("<script language=javascript>alert('更新成功！')</script>");
            con.Close();

        }
        catch (Exception ex)
        {
            Response.Write(ex);
        }
    }
    }
